﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PhotoGallery.Model;
using PhotoGallery.BLL;
public partial class Admin : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        User u = (User)Session["user"];
        if (u != null) 
        {
            if (u.Role == "1")
            {
                this.user.Text = u.Nickname;
                //判断是否有头像相册，如果有，则显示头像，如果没有则显示默认头像
                Picture avatorImg = getAvator(u.Uid);
                if (avatorImg != null)
                {
                    this.avt.ImageUrl = avatorImg.Pic;
                }
                else
                {
                    this.avt.ImageUrl = "Images/user.png";
                }
            }
            else 
            {
                Response.Redirect("login.aspx");
            }
        } 
        else
        {
            Response.Redirect("login.aspx");
        }
    }

    //判断是否有头像相册,如果有，则返回头像，如果没有，返回null
    private Picture getAvator(string uid)
    {
        AlbumAction aa = new AlbumAction();
        PhotoAction pa = new PhotoAction();
        List<Albums> alist = aa.allAlbumsofSomeone(uid);//取得某用户的所有相册
        if (alist.Count == 0) return null;//无相册，返回空
        //有相册
        foreach (Albums a in alist)
        {
            if (a.Title == "头像相册" && a.Desp == "头像相册")//有头像相册
            {
                return pa.showCover(a.Aid);
            }
            else //不是头像相册
            {

            }
        }
        return null;
    }
}
